#ifndef EQUIPMENT_H
#define EQUIPMENT_H

// 装备强化加的数值
#define WEPON_REINFORCEMENT_20 583 // 武器+20数值
#define JEWELRY_REINFORCEMENT_20 3*64 // 3件首饰+20数值
#define ARMOR_REINFORCEMENT_20 5*48 // 5件防具+20数值
#define AUXILIARY_REINFORCEMENT_20 70 // 辅助装备+20数值

// 防具精通加的数值
#define ARMOR_MASTERY 113   // 50级防具精通加的力智值为112.2,往后每个等级的装备+5力智
                            // 这里只取整数且按最低值计算

// 徽章加的数值
#define RED_BADGE               45*6 // 8级力智
#define GREEN_BADGE             39*4 // 8级暴击

#include <QCloseEvent>
#include <QDialog>
#include <QFile>
#include <QFileDialog>
#include <QSettings>
#include <QMap>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QMessageBox>
#include <QUrl>
#include <QUrlQuery>
#include <QBuffer>

QT_BEGIN_NAMESPACE
namespace Ui {
class AddEquip;
}
QT_END_NAMESPACE

class AddEquip : public QDialog
{
    Q_OBJECT
public:
    AddEquip(QWidget *parent = nullptr);
    ~AddEquip();
    // 只能选中一个checkbox
    void checkBoxOnlyOne();
    // 发送获取orc功能验证码请求
    void requestAccessToken();
    // 发送ocr识别请求
    void requestOcrResults();
    // 处理从图片读出的文字
    void processPictureValue(const QString& strContain, QString str);
    // 填入相关属性值
    void entryValueIntoSpinbox(int num);
    // 写入装备信息
    void writeWeponInfo(QJsonObject &rootObject);
    void writeArmorInfo(QJsonObject &rootObject);
    void writeJewelryInfo(QJsonObject &rootObject);
    void writeAuxiliaryInfo(QJsonObject &rootObject);
    void writeDataIntoJson();
    // QDialog当前页面数据复位成null
    void resetCurrentIndexData();

public slots:
    void accept() override;
    void reject() override;
    void changeStackWidgetIndex(int index);
    void getReply(QNetworkReply* reply);
    void readPictureValue();

private:
    Ui::AddEquip *ui;
    QNetworkAccessManager networkManager;
    QString accessToken;
    QByteArray base64img;
    // 属性
    int ad_strength = 0;
    int ad_intelligence = 0;
    int ad_physicalAttack = 0;
    int ad_magicalAttack = 0;
    int ad_physicalCriticalProb = 0;
    int ad_magicalCriticalProb = 0;
    int ad_physicalCriticalValue = 0;
    int ad_magicalCriticalValue = 0;
    int ad_strengthBonus = 0;
    int ad_intelligenceBonus = 0;
    int ad_physicalAttackBonus = 0;
    int ad_magicalAttackBonus = 0;
    int ad_skillBonus = 0;
    int ad_damageBonus = 0;
    int ad_criticalDamageBonus = 0;
    int ad_extraDamageBonus = 0;
    int ad_elementExtraDamageBonus = 0;
    int ad_elementBonus = 0;
    // 装备图片包含的属性文字
    const QString _STR = tr("力量+");
    const QString _INT = tr("智力+");
    const QString _PATK = tr("物理攻击力+");
    const QString _MATK = tr("魔法攻击力+");
    const QString _PCRIP = tr("物理暴击率+");
    const QString _MCRIP = tr("魔法暴击率+");
    const QString _PCRIV = tr("物理暴击+");
    const QString _MCRIV = tr("魔法暴击+");
    const QString _SKI = tr("技能攻击力+");
    const QString _DAM = tr("伤害+");
    const QString _ELE = tr("属性强化+");
    const QString _CRIDAM = tr("暴击伤害+");
    const QString _EXT = tr("的伤害");  // 白字
    const QString _ELEEXT = tr("属性伤害"); // 属白
    // 写入json文件的属性文字
    const QString JSON_STR = tr("力量");
    const QString JSON_INT = tr("智力");
    const QString JSON_STRB = tr("力量加成");
    const QString JSON_INTB = tr("智力加成");
    const QString JSON_PATK = tr("物理攻击力");
    const QString JSON_MATK = tr("魔法攻击力");
    const QString JSON_PATKB = tr("物攻加成");
    const QString JSON_MATKB = tr("魔攻加成");
    const QString JSON_PCRIP = tr("物理暴击率");
    const QString JSON_MCRIP = tr("魔法暴击率");
    const QString JSON_PCRIV = tr("物理暴击");
    const QString JSON_MCRIV = tr("魔法暴击");
    const QString JSON_SKIB = tr("技能攻击");
    const QString JSON_DAMB = tr("黄字");
    const QString JSON_ELEB = tr("属性强化");
    const QString JSON_CRIDAMB = tr("暴伤");
    const QString JSON_EXTB = tr("白字");
    const QString JSON_ELEEXTB = tr("属白");
};

#endif // EQUIPMENT_H
